#include "../collections.hpp"

using lms::collections::Node;
using lms::collections::Stack;

template<class TEntity>
Stack<TEntity>::Stack()
{
    first = 0;
    last = 0;                       
}

template<class TEntity>
Node<TEntity>* Stack<TEntity>::getFirst()
{
    return first;               
}

template<class TEntity>
Node<TEntity>* Stack<TEntity>::getLast()
{
    return last;               
}

template<class TEntity>
int Stack<TEntity>::getLength()
{
    return length;    
}

template<class TEntity>
void Stack<TEntity>::push(TEntity* entity)
{
     Node<TEntity> *tempNode = new Node<TEntity>();
     tempNode->setData(entity);
     if(last == 0)
     {
         first = tempNode;
         last = tempNode;     
     }else
     {
         tempNode->setPrevious(entity);
         last = tempNode;     
     }
}

template<class TEntity>
Node<TEntity>* Stack<TEntity>::pop()
{
     if(last == 0)
     {
         return 0;        
     }
     Node<TEntity> *tempNode = last;
     last = last->getPrevious();
     return tempNode;
     
}
